<?php 
//session_start();
include("helper/DBOperation.php");
include("alert_loader.php");
$dbObj = new DBOperation();
//	echo "<pre>";print_r($row_componentcpu);

include("helper/check_user_login.php");
checkUserIsLogin();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name = "viewport" content = "width = device-width">

<meta name="apple-mobile-web-app-capable" content="yes" />

<title>HBMS - Component CPU</title>
<link href="HBMS_css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
// Mobile Safari in standalone mode
if(("standalone" in window.navigator) && window.navigator.standalone){

// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
var noddy, remotes = false;

document.addEventListener('click', function(event) {

noddy = event.target;

// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}

if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
event.preventDefault();
document.location.href = noddy.href;
}

},false);
}

</script>


</head>

<body>

<div id="component_cpu_main">
	<div class="unit_a_content">
    
    	<div class="unit_a_top_row">
        	<div class="unit_a_cemusa_img"></div>
		<?php if($cookie['userslog']['is_admin']==1){ ?>
				<a href="admin/user_listing.php" style="text-decoration:none;color:white;"><img src="images/person.png" width="20px" height="20px" title="Add User"/></a>
			<?php }?>
            <div class="unita_top_text_part">
            	<div class="unita_top_txt1"><span>logged in as:</span> <?=$cookie['userslog']['display_name']?></div>
                <div class="unita_top_txt1"><span>last update:</span> 
		<?php if($lastLogUpdateTime = $dbObj->lastUpdatedLogTime()) { echo $lastLogUpdateTime; } else { echo "00:00:00"; } ?></div>
            </div>
        </div>
        <?php
	$device_id = $_REQUEST['did'];
	$component_id = $_REQUEST['cid'];
	$result_devicename = array();
	if($device_id) {
		$result_devicename = $dbObj->executeQuery("SELECT device_name FROM tbl_device where id=".$device_id , true);
		
	$row_componentcpu = $dbObj->executeQuery("SELECT * FROM tbl_component_cpu where component_id='".$component_id."' ORDER BY id DESC LIMIT 1" , true);
	}
?>
        
        <div class="component_cpu_middle_content">
        
        	<div class="system_unit_row">
                <div class="system_top_home_bttn"><a href="system.php?id=<?php echo $device_id; ?>">Unit</a></div>
		<?php
			$qry = "select * from tbl_component_state where component_id='".$component_id."' order by id DESC limit 1";
			$result = mysql_query($qry);
			$total = mysql_num_rows($result);	
			$x = 0;
			$color_state = array();
			while($row=mysql_fetch_array($result))
				$color_state[] = $row['state'];
			$barColor = "blue";
			if(isset($color_state[0])) {
				$barColor = $color_state[0];	
			}
		?>
                <div class="component_cpu_txt"><div class="bar" style="background:<?php echo $barColor; ?>"></div>
                	<div class="component_cpu_txt1"><?php if(isset($result_devicename['device_name'])) { 
			echo $result_devicename['device_name']; } ?></div>
                    <div class="component_cpu_txt2">CPUV</div>
                </div>
				
                <div class="system_unit_icon"><a href="alert_log_cpuv.php?cid=<?=$component_id;?>
&did=<?=$device_id;?>"></a></div>
				
            </div>
            
            <div class="component_cpu_middle_txt bigText">
            	<h2>CPU Info</h2>
            	<div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">cpu name:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['cpu_name']; ?></div>
			<div class="clear"></div>
                </div> 
                <div class="component_middle_txt_row">
                  <div class="component_middle_txt_name_left">ip address:</div>
                   <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['ip_address']; ?></div>
			<div class="clear"></div>
                </div> 
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">last ping:</div>
                    <div class="component_middle_txt_name_right">
							<?php	$colorLastPing = "white";

								$lastPingTime		= $row_componentcpu['last_ping'] ;
								
								$lastPingTime = date('Y-m-d H:i:s',strtotime($lastPingTime));						
								$secondLastPing = date('Y-m-d H:i:s');
															
								
								$pingDifference		= strtotime($secondLastPing) - strtotime($lastPingTime) ;
								$pingDifference		= round($pingDifference/60);									
								
								
								if($pingDifference > $lastPingYellowCPU ) {
									if($pingDifference <= $lastPingRedCPU){										
										$colorLastPing = "yellow";
									}else{			
										$colorLastPing = "red";
									}		
								}
									
							?>

						<span style="color:<?php echo $colorLastPing;?>">
							<?php echo $row_componentcpu['last_ping']?date('Y-m-d h:i:s A',strtotime($row_componentcpu['last_ping'])):""; ?>
						</span>
					</div>
			<div class="clear"></div>
                </div>   
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">current status:</div>
                    <div class="component_middle_txt_name_right">
						<?php $colorStatus = "white";
							
							  if($row_componentcpu['current_status']=="offline"){
								$colorStatus = "red";
							  }?>
						<span style="color:<?php echo $colorStatus;?>">
						<?php echo $row_componentcpu['current_status']; ?>
						</span>
					</div>
			<div class="clear"></div>
                </div>
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">cpu temp:</div>
                    <div class="component_middle_txt_name_right">
						<?php $colorTemp = "white";
							  if($row_componentcpu['cpu_temp'] < $cpuTempYellowLow || $row_componentcpu['cpu_temp'] > $cpuTempYellowHigh) {		
								$colorTemp = "yellow";
							  }?>
						<span style="color:<?php echo $colorTemp;?>">
						<?php echo $row_componentcpu['cpu_temp']; ?>
						</span>
					</div>
			<div class="clear"></div>
                </div>  
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">network speed:</div>
                    <div class="component_middle_txt_name_right">
						<?php $colorSpeed = "white";
							   if($row_componentcpu['network_speed']< $ntwspdYellowHigh && $row_componentcpu['network_speed'] > $ntwspdYellowLow) {		
								$colorSpeed = "yellow";
							  }elseif($row_componentcpu['network_speed'] == $ntwspdRed ) {
								$colorSpeed = "red";
							  } ?>
						<span style="color:<?php echo $colorSpeed;?>">
						<?php echo $row_componentcpu['network_speed']; ?>
						</span>
					</div>
			<div class="clear"></div>
                </div>  
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">os version:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['os_version']; ?></div>
			<div class="clear"></div>
                </div>  
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">player vers:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['player_vers']; ?></div>
			<div class="clear"></div>
                </div>  
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">last reboot:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['last_reboot']; ?></div>
			<div class="clear"></div>
                </div> 
                 <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">free HD space:</div>
                    <div class="component_middle_txt_name_right">
						<?php $colorSpace = "white";
							  if($row_componentcpu['free_hd_space']< $hdspaceYellowHigh && $row_componentcpu['free_hd_space'] >= $hdspaceYellowHigh) {		
								$colorSpace = "yellow";
							  }elseif($row_componentcpu['free_hd_space'] < $hdspaceRed ) {
								$colorSpace = "red";
							  }?>
						<span style="color:<?php echo $colorSpace;?>">
						<?php echo $row_componentcpu['free_hd_space']; ?>
						</span>							
					</div>
			<div class="clear"></div>
                </div> 
                <h2 class="space">Content Info</h2>
                
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">schedule name:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['schedule_name']; ?></div>
			<div class="clear"></div>
                </div> 
                <div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">last sched upload:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['last_sched_upload']; ?></div>
			<div class="clear"></div>
                </div> 
	<div class="component_middle_txt_row">
                	<div class="component_middle_txt_name_left">schedule file size:</div>
                    <div class="component_middle_txt_name_right"><?php echo $row_componentcpu['schedule_file_size']; ?></div>
			<div class="clear"></div>
                </div> 
             </div>

             </div>

            
        </div>
        
        <div class="unita_showtell_row">
        	<div class="unita_showtell_img"></div>
        </div>
        
        <div class="unita_bottm_menu">
        	<?php include("footer.php");?>
        </div>
        
        
    </div>
</div>



</body>
</html>



    
